home *** CD-ROM | disk | FTP | other *** search
/ Tech Win 1995 November / CD [TECH_B].bin / tech_b / delphi / trial / disk4 / doc.pak / SYSUTILS.INT < prev    next >
Encoding:
Text File  |  1995-08-08  |  60.4 KB  |  1,468 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       System Utilities Unit                           }
  6. {                                                       }
  7. {       Copyright (C) 1995 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit SysUtils;
  12.  
  13. {$N+,P+,S-,G+}
  14.  
  15.  
  16. {$C MOVEABLE PRELOAD PERMANENT}
  17.  
  18. interface
  19.  
  20. const
  21.  
  22. { File open modes }
  23.  
  24.   fmOpenRead       = $0000;
  25.   fmOpenWrite      = $0001;
  26.   fmOpenReadWrite  = $0002;
  27.   fmShareCompat    = $0000;
  28.   fmShareExclusive = $0010;
  29.   fmShareDenyWrite = $0020;
  30.   fmShareDenyRead  = $0030;
  31.   fmShareDenyNone  = $0040;
  32.  
  33. { File attribute constants }
  34.  
  35.   faReadOnly  = $01;
  36.   faHidden    = $02;
  37.   faSysFile   = $04;
  38.   faVolumeID  = $08;
  39.   faDirectory = $10;
  40.   faArchive   = $20;
  41.   faAnyFile   = $3F;
  42.  
  43. { File mode magic numbers }
  44.  
  45.   fmClosed = $D7B0;
  46.   fmInput  = $D7B1;
  47.   fmOutput = $D7B2;
  48.   fmInOut  = $D7B3;
  49.  
  50. { Seconds and milliseconds per day }
  51.  
  52.   SecsPerDay = 24 * 60 * 60;
  53.   MSecsPerDay = SecsPerDay * 1000;
  54.  
  55. type
  56.  
  57. { Type conversion records }
  58.  
  59.   WordRec = record
  60.     Lo, Hi: Byte;
  61.   end;
  62.  
  63.   LongRec = record
  64.     Lo, Hi: Word;
  65.   end;
  66.  
  67.   PtrRec = record
  68.     Ofs, Seg: Word;
  69.   end;
  70.  
  71.   TMethod = record
  72.     Code, Data: Pointer;
  73.   end;
  74.  
  75. { General arrays }
  76.  
  77.   PByteArray = ^TByteArray;
  78.   TByteArray = array[0..32767] of Byte;
  79.  
  80.   PWordArray = ^TWordArray;
  81.   TWordArray = array[0..16383] of Word;
  82.  
  83. { Generic procedure pointer }
  84.  
  85.   TProcedure = procedure;
  86.  
  87. { Generic filename type }
  88.  
  89.   TFileName = string[79];
  90.  
  91. { Search record used by FindFirst, FindNext, and FindClose }
  92.  
  93.   TSearchRec = record
  94.     Fill: array[1..21] of Byte;
  95.     Attr: Byte;
  96.     Time: Longint;
  97.     Size: Longint;
  98.     Name: string[12];
  99.   end;
  100.  
  101. { Typed-file and untyped-file record }
  102.  
  103.   TFileRec = record
  104.     Handle: Word;
  105.     Mode: Word;
  106.     RecSize: Word;
  107.     Private: array[1..26] of Byte;
  108.     UserData: array[1..16] of Byte;
  109.     Name: array[0..79] of Char;
  110.   end;
  111.  
  112. { Text file record structure used for Text files }
  113.  
  114.   PTextBuf = ^TTextBuf;
  115.   TTextBuf = array[0..127] of Char;
  116.   TTextRec = record
  117.     Handle: Word;
  118.     Mode: Word;
  119.     BufSize: Word;
  120.     Private: Word;
  121.     BufPos: Word;
  122.     BufEnd: Word;
  123.     BufPtr: PTextBuf;
  124.     OpenFunc: Pointer;
  125.     InOutFunc: Pointer;
  126.     FlushFunc: Pointer;
  127.     CloseFunc: Pointer;
  128.     UserData: array[1..16] of Byte;
  129.     Name: array[0..79] of Char;
  130.     Buffer: TTextBuf;
  131.   end;
  132.  
  133. { FloatToText format codes }
  134.  
  135.   TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  136.  
  137. { FloatToDecimal result record }
  138.  
  139.   TFloatRec = record
  140.     Exponent: Integer;
  141.     Negative: Boolean;
  142.     Digits: array[0..18] of Char;
  143.   end;
  144.  
  145. { Exceptions }
  146.  
  147.   Exception = class(TObject)
  148.   public
  149.     constructor Create(const Msg: string);
  150.     constructor CreateFmt(const Msg: string; const Args: array of const);
  151.     constructor CreateRes(Ident: Word);
  152.     constructor CreateResFmt(Ident: Word; const Args: array of const);
  153.     constructor CreateHelp(const Msg: string; AHelpContext: Longint);
  154.     constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  155.       AHelpContext: Longint);
  156.     constructor CreateResHelp(Ident: Word; AHelpContext: Longint);
  157.     constructor CreateResFmtHelp(Ident: Word; const Args: array of const;
  158.       AHelpContext: Longint);
  159.     destructor Destroy; override;
  160.     property HelpContext: Longint;
  161.     property Message: string;
  162.     property MessagePtr: PString;
  163.   end;
  164.  
  165.   ExceptClass = class of Exception;
  166.  
  167.   EAbort = class(Exception);
  168.  
  169.   EOutOfMemory = class(Exception)
  170.   public
  171.     destructor Destroy; override;
  172.     procedure FreeInstance; override;
  173.   end;
  174.  
  175.   EInOutError = class(Exception)
  176.   public
  177.     ErrorCode: Integer;
  178.   end;
  179.  
  180.   EIntError = class(Exception);
  181.   EDivByZero = class(EIntError);
  182.   ERangeError = class(EIntError);
  183.   EIntOverflow = class(EIntError);
  184.  
  185.   EMathError = class(Exception);
  186.   EInvalidOp = class(EMathError);
  187.   EZeroDivide = class(EMathError);
  188.   EOverflow = class(EMathError);
  189.   EUnderflow = class(EMathError);
  190.  
  191.   EInvalidPointer = class(Exception);
  192.  
  193.   EInvalidCast = class(Exception);
  194.  
  195.   EConvertError = class(Exception);
  196.  
  197.   EProcessorException = class(Exception);
  198.   EFault = class(EProcessorException);
  199.   EGPFault = class(EFault);
  200.   EStackFault = class(EFault);
  201.   EPageFault = class(EFault);
  202.   EInvalidOpCode = class(EFault);
  203.   EBreakpoint = class(EProcessorException);
  204.   ESingleStep = class(EProcessorException);
  205.  
  206. { Fault handler response }
  207.  
  208.   TFaultResponse = (frKill, frResume, frChain);
  209.  
  210. { Fault handler function type }
  211.  
  212.   TFaultHandler = function(FaultID: Word;
  213.     FaultAddress: Pointer): TFaultResponse;
  214.  
  215. { Processor exception hook }
  216.  
  217. const
  218.   ProcessorExceptHook: TFaultHandler = nil;
  219.   HandleDebugInts: Boolean = False;
  220.  
  221. { Null string pointer }
  222.  
  223. const
  224.   EmptyStr: string[1] = '';
  225.   NullStr: PString = @EmptyStr;
  226.  
  227. { Currency and date/time formatting options }
  228.  
  229. { CurrencyString - Defines the currency symbol used in floating-point to
  230.   decimal conversions. The initial value is fetched from the sCurrency
  231.   variable in the [intl] section of WIN.INI.
  232.  
  233.   CurrencyFormat - Defines the currency symbol placement and separation
  234.   used in floating-point to decimal conversions. Possible values are:
  235.  
  236.     0 = '$1'
  237.     1 = '1$'
  238.     2 = '$ 1'
  239.     3 = '1 $'
  240.  
  241.   The initial value is fetched from the iCurrency variable in the [intl]
  242.   section of WIN.INI.
  243.  
  244.   NegCurrFormat - Defines the currency format for used in floating-point to
  245.   decimal conversions of negative numbers. Possible values are:
  246.  
  247.     0 = '($1)'          4 = '(1$)'          8 = '-1 $'
  248.     1 = '-$1'           5 = '-1$'           9 = '-$ 1'
  249.     2 = '$-1'           6 = '1-$'          10 = '$ 1-'
  250.     3 = '$1-'           7 = '1$-'
  251.  
  252.   The initial value is fetched from the iNegCurr variable in the [intl]
  253.   section of WIN.INI.
  254.  
  255.   ThousandSeparator - The character used to separate thousands in numbers
  256.   with more than three digits to the left of the decimal separator. The
  257.   initial value is fetched from the sThousand variable in the [intl] section
  258.   of WIN.INI.
  259.  
  260.   DecimalSeparator - The character used to separate the integer part from
  261.   the fractional part of a number. The initial value is fetched from the
  262.   sDecimal variable in the [intl] section of WIN.INI.
  263.  
  264.   CurrencyDecimals - The number of digits to the right of the decimal point
  265.   in a currency amount. The initial value is fetched from the sCurrDigits
  266.   variable in the [intl] section of WIN.INI.
  267.  
  268.   DateSeparator - The character used to separate the year, month, and day
  269.   parts of a date value. The initial value is fetched from the sDate
  270.   variable in the [intl] section of WIN.INI.
  271.  
  272.   ShortDateFormat - The format string used to convert a date value to a
  273.   short string suitable for editing. For a complete description of date and
  274.   time format strings, refer to the documentation for the FormatDate
  275.   function. The short date format should only use the date separator
  276.   character and the  m, mm, d, dd, yy, and yyyy format specifiers. The
  277.   initial value is fetched from the sShortDate variable in the [intl]
  278.   section of WIN.INI.
  279.  
  280.   LongDateFormat - The format string used to convert a date value to a long
  281.   string suitable for display but not for editing. For a complete description
  282.   of date and time format strings, refer to the documentation for the
  283.   FormatDate function. The initial value is fetched from the sLongDate
  284.   variable in the [intl] section of WIN.INI.
  285.  
  286.   TimeSeparator - The character used to separate the hour, minute, and
  287.   second parts of a time value. The initial value is fetched from the sTime
  288.   variable in the [intl] section of WIN.INI.
  289.  
  290.   TimeAMString - The suffix string used for time values between 00:00 and
  291.   11:59 in 12-hour clock format. The initial value is fetched from the s1159
  292.   variable in the [intl] section of WIN.INI.
  293.  
  294.   TimePMString - The suffix string used for time values between 12:00 and
  295.   23:59 in 12-hour clock format. The initial value is fetched from the s2359
  296.   variable in the [intl] section of WIN.INI.
  297.  
  298.   ShortTimeFormat - The format string used to convert a time value to a
  299.   short string with only hours and minutes. The default value is computed
  300.   from the iTime and iTLZero variables in the [intl] section of WIN.INI.
  301.  
  302.   LongTimeFormat - The format string used to convert a time value to a long
  303.   string with hours, minutes, and seconds. The default value is computed
  304.   from the iTime and iTLZero variables in the [intl] section of WIN.INI.
  305.  
  306.   ShortMonthNames - Array of strings containing short month names. The mmm
  307.   format specifier in a format string passed to FormatDate causes a short
  308.   month name to be substituted.
  309.  
  310.   LongMonthNames - Array of strings containing long month names. The mmmm
  311.   format specifier in a format string passed to FormatDate causes a long
  312.   month name to be substituted.
  313.  
  314.   ShortDayNames - Array of strings containing short day names. The ddd
  315.   format specifier in a format string passed to FormatDate causes a short
  316.   day name to be substituted.
  317.  
  318.   LongDayNames - Array of strings containing long day names. The dddd
  319.   format specifier in a format string passed to FormatDate causes a long
  320.   day name to be substituted. }
  321.  
  322. var
  323.   CurrencyString: string[7];
  324.   CurrencyFormat: Byte;
  325.   NegCurrFormat: Byte;
  326.   ThousandSeparator: Char;
  327.   DecimalSeparator: Char;
  328.   CurrencyDecimals: Byte;
  329.   DateSeparator: Char;
  330.   ShortDateFormat: string[15];
  331.   LongDateFormat: string[31];
  332.   TimeSeparator: Char;
  333.   TimeAMString: string[7];
  334.   TimePMString: string[7];
  335.   ShortTimeFormat: string[15];
  336.   LongTimeFormat: string[31];
  337.   ShortMonthNames: array[1..12] of string[7];
  338.   LongMonthNames: array[1..12] of string[15];
  339.   ShortDayNames: array[1..7] of string[7];
  340.   LongDayNames: array[1..7] of string[15];
  341.  
  342. { Memory management routines }
  343.  
  344. { AllocMem allocates a block of the given size on the heap. Each byte in
  345.   the allocated buffer is set to zero. To dispose the buffer, use the
  346.   FreeMem standard procedure. }
  347.  
  348. function AllocMem(Size: Cardinal): Pointer;
  349.  
  350. { ReAllocMem re-allocates a block. On entry, P points to an existing heap
  351.   block, CurSize gives the current size of the heap block, and NewSize
  352.   specifies the requested new size of the block. If CurSize is less than
  353.   NewSize, the additional bytes in the new buffer are set to zero. The
  354.   returned value is a pointer to the new block; this value is always
  355.   different from the original pointer. }
  356.  
  357. function ReAllocMem(P: Pointer; CurSize, NewSize: Cardinal): Pointer;
  358.  
  359. { Exit procedure handling }
  360.  
  361. { AddExitProc adds the given procedure to the run-time library's exit
  362.   procedure list. When an application terminates, its exit procedures are
  363.   executed in reverse order of definition, i.e. the last procedure passed
  364.   to AddExitProc is the first one to get executed upon termination. }
  365.  
  366. procedure AddExitProc(Proc: TProcedure);
  367.  
  368. { CallExitProcs executes all installed exit procedures. The exit procedures
  369.   are executed in reversed order of definition, i.e. the last one installed
  370.   is the first one to get executed. As the procedures are executed, they
  371.   are removed from the exit procedure chain. Thus, following a call to
  372.   CallExitProcs, the ExitProc variable (defined in the System unit) will
  373.   be NIL. }
  374.  
  375. procedure CallExitProcs;
  376.  
  377. { String handling routines }
  378.  
  379. { NewStr allocates a copy of the given string on the heap. The size of the
  380.   allocated heap block is Length(S) + 1. If the string is empty, NewStr
  381.   returns NullStr and doesn't allocate any heap space. To dispose the
  382.   string, use DisposeStr. }
  383.  
  384. function NewStr(const S: String): PString;
  385.  
  386. { DisposeStr disposes a string pointer that was previously allocated using
  387.   NewStr. If the given pointer is NIL or points to an empty string,
  388.   StrDispose does nothing. }
  389.  
  390. procedure DisposeStr(P: PString);
  391.  
  392. { AssignStr assigns a new dynamically allocated string to the given string
  393.   pointer. AssignStr corresponds to the statement "DisposeStr(P)" followed
  394.   by the statement "P := NewStr(S)". Note that P must be NIL or contain a
  395.   valid string pointer before calling AssignStr. In other words, AssignStr
  396.   cannot be used to initialize a string pointer variable. }
  397.  
  398. procedure AssignStr(var P: PString; const S: string);
  399.  
  400. { AppendStr appends S to the end of Dest. AppendStr corresponds to the
  401.   statement "Dest := Dest + S", but is more efficient. }
  402.  
  403. procedure AppendStr(var Dest: string; const S: string);
  404.  
  405. { UpperCase converts all ASCII characters in the given string to upper case.
  406.   The conversion affects only 7-bit ASCII characters between 'a' and 'z'. To
  407.   convert 8-bit international characters, use AnsiUpperCase. }
  408.  
  409. function UpperCase(const S: string): string;
  410.  
  411. { UpperCase converts all ASCII characters in the given string to lower case.
  412.   The conversion affects only 7-bit ASCII characters between 'A' and 'Z'. To
  413.   convert 8-bit international characters, use AnsiLowerCase. }
  414.  
  415. function LowerCase(const S: string): string;
  416.  
  417. { CompareStr compares S1 to S2, with case-sensitivity. The return value is
  418.   less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. The
  419.   compare operation is based on the 8-bit ordinal value of each character
  420.   and is not affected by the currently installed language driver. }
  421.  
  422. function CompareStr(const S1, S2: string): Integer;
  423.  
  424. { CompareText compares S1 to S2, without case-sensitivity. The return value
  425.   is the same as for CompareStr. The compare operation is based on the 8-bit
  426.   ordinal value of each character, after converting 'a'..'z' to 'A'..'Z',
  427.   and is not affected by the currently installed language driver. }
  428.  
  429. function CompareText(const S1, S2: string): Integer;
  430.  
  431. { AnsiUpperCase converts all characters in the given string to upper case.
  432.   The conversion uses the currently installed language driver. }
  433.  
  434. function AnsiUpperCase(const S: string): string;
  435.  
  436. { AnsiLowerCase converts all characters in the given string to lower case.
  437.   The conversion uses the currently installed language driver. }
  438.  
  439. function AnsiLowerCase(const S: string): string;
  440.  
  441. { AnsiCompareStr compares S1 to S2, with case-sensitivity. The compare
  442.   operation is controlled by the currently installed language driver. The
  443.   return value is the same as for CompareStr. }
  444.  
  445. function AnsiCompareStr(const S1, S2: string): Integer;
  446.  
  447. { AnsiCompareText compares S1 to S2, without case-sensitivity. The compare
  448.   operation is controlled by the currently installed language driver. The
  449.   return value is the same as for CompareStr. }
  450.  
  451. function AnsiCompareText(const S1, S2: string): Integer;
  452.  
  453. { IsValidIdent returns true if the given string is a valid identifier. An
  454.   identifier is defined as a character from the set ['A'..'Z', 'a'..'z', '_']
  455.   followed by zero or more characters from the set ['A'..'Z', 'a'..'z',
  456.   '0..'9', '_']. }
  457.  
  458. function IsValidIdent(const Ident: string): Boolean;
  459.  
  460. { IntToStr converts the given value to its decimal string representation. }
  461.  
  462. function IntToStr(Value: Longint): string;
  463.  
  464. { IntToHex converts the given value to a hexadecimal string representation
  465.   with the minimum number of digits specified. }
  466.  
  467. function IntToHex(Value: Longint; Digits: Integer): string;
  468.  
  469. { StrToInt converts the given string to an integer value. If the string
  470.   doesn't contain a valid value, an EConvertError exception is raised. }
  471.  
  472. function StrToInt(const S: string): Longint;
  473.  
  474. { StrToIntDef converts the given string to an integer value. If the string
  475.   doesn't contain a valid value, the value given by Default is returned. }
  476.  
  477. function StrToIntDef(const S: string; Default: Longint): Longint;
  478.  
  479. { LoadStr loads the string resource given by Ident from the application's
  480.   executable file. If the string resource does not exist, an empty string
  481.   is returned. }
  482.  
  483. function LoadStr(Ident: Word): string;
  484.  
  485. { LoadStr loads the string resource given by Ident from the application's
  486.   executable file, and uses it as the format string in a call to the
  487.   Format function with the given arguments. }
  488.  
  489. function FmtLoadStr(Ident: Word; const Args: array of const): string;
  490.  
  491. { File management routines }
  492.  
  493. { FileOpen opens the specified file using the specified access mode. The
  494.   access mode value is constructed by OR-ing one of the fmOpenXXXX constants
  495.   with one of the fmShareXXXX constants. If the return value is positive,
  496.   the function was successful and the value is the file handle of the opened
  497.   file. If the return value is negative, an error occurred and the value is
  498.   a negative DOS error code. }
  499.  
  500. function FileOpen(const FileName: string; Mode: Word): Integer;
  501.  
  502. { FileCreate creates a new file by the specified name. If the return value
  503.   is positive, the function was successful and the value is the file handle
  504.   of the new file. If the return value is negative, an error occurred and
  505.   the value is a negative DOS error code. }
  506.  
  507. function FileCreate(const FileName: string): Integer;
  508.  
  509. { FileRead reads Count bytes from the file given by Handle into the buffer
  510.   specified by Buffer. The return value is the number of bytes actually
  511.   read; it is less than Count if the end of the file was reached. The return
  512.   value is -1 if an error occurred. }
  513.  
  514. function FileRead(Handle: Integer; var Buffer; Count: Longint): Longint;
  515.  
  516. { FileWrite writes Count bytes to the file given by Handle from the buffer
  517.   specified by Buffer. The return value is the number of bytes actually
  518.   written, or -1 if an error occurred. }
  519.  
  520. function FileWrite(Handle: Integer; const Buffer; Count: Longint): Longint;
  521.  
  522. { FileSeek changes the current position of the file given by Handle to be
  523.   Offset bytes relative to the point given by Origin. Origin = 0 means that
  524.   Offset is relative to the beginning of the file, Origin = 1 means that
  525.   Offset is relative to the current position, and Origin = 2 means that
  526.   Offset is relative to the end of the file. The return value is the new
  527.   current position, relative to the beginning of the file, or -1 if an error
  528.   occurred. }
  529.  
  530. function FileSeek(Handle: Integer; Offset: Longint; Origin: Integer): Longint;
  531.  
  532. { FileClose closes the specified file. }
  533.  
  534. procedure FileClose(Handle: Integer);
  535.  
  536. { FileAge returns the date-and-time stamp of the specified file. The return
  537.   value can be converted to a TDateTime value using the FileDateToDateTime
  538.   function. The return value is -1 if the file does not exist. }
  539.  
  540. function FileAge(const FileName: string): Longint;
  541.  
  542. { FileExists returns a boolean value that indicates whether the specified
  543.   file exists. }
  544.  
  545. function FileExists(const FileName: string): Boolean;
  546.  
  547. { FindFirst searches the directory given by Path for the first entry that
  548.   matches the filename given by Path and the attributes given by Attr. The
  549.   result is returned in the search record given by SearchRec. The return
  550.   value is zero if the function was successful. Otherwise the return value
  551.   is a negative DOS error code; a value of -18 indicates that no files were
  552.   found. FindFirst is typically used in conjunction with FindNext and
  553.   FindClose as follows:
  554.  
  555.     Result := FindFirst(Path, Attr, SearchRec);
  556.     while Result = 0 do
  557.     begin
  558.       ProcessSearchRec(SearchRec);
  559.       Result := FindNext(SearchRec);
  560.     end;
  561.     FindClose(SearchRec);
  562.  
  563.   where ProcessSearchRec represents user-defined code that processes the
  564.   information in a search record. }
  565.  
  566. function FindFirst(const Path: string; Attr: Integer;
  567.   var SearchRec: TSearchRec): Integer;
  568.  
  569. { FindNext returs the next entry that matches the name and attributes
  570.   specified in a previous call to FindFirst. The search record must be one
  571.   that was passed to FindFirst. The return value is zero if the function was
  572.   successful. Otherwise the return value is a negative DOS error code; a
  573.   value of -18 indicates that there are no more files matching the search
  574.   criteria. }
  575.  
  576. function FindNext(var SearchRec: TSearchRec): Integer;
  577.  
  578. { FindClose terminates a FindFirst/FindNext sequence. FindClose does nothing
  579.   in the 16-bit version of Windows, but is required in the 32-bit version,
  580.   so for maximum portability every FindFirst/FindNext sequence should end
  581.   with a call to FindClose. }
  582.  
  583. procedure FindClose(var SearchRec: TSearchRec);
  584.  
  585. { FileGetDate returns the DOS date-and-time stamp of the file given by
  586.   Handle. The return value is -1 if the handle is invalid. The
  587.   FileDateToDateTime function can be used to convert the returned value to
  588.   a TDateTime value. }
  589.  
  590. function FileGetDate(Handle: Integer): Longint;
  591.  
  592. { FileSetDate sets the DOS date-and-time stamp of the file given by Handle
  593.   to the value given by Age. The DateTimeToFileDate function can be used to
  594.   convert a TDateTime value to a DOS date-and-time stamp. }
  595.  
  596. procedure FileSetDate(Handle: Integer; Age: Longint);
  597.  
  598. { FileGetAttr returns the file attributes of the file given by FileName. The
  599.   attributes can be examined by AND-ing with the faXXXX constants defined
  600.   above. If the return value is negative, an error occurred and the value is
  601.   a negative DOS error code. }
  602.  
  603. function FileGetAttr(const FileName: string): Integer;
  604.  
  605. { FileSetAttr sets the file attributes of the file given by FileName to the
  606.   value given by Attr. The attribute value is formed by OR-ing the
  607.   appropriate faXXXX constants. The return value is zero if the function was
  608.   successful. Otherwise the return value is a negative DOS error code. }
  609.  
  610. function FileSetAttr(const FileName: string; Attr: Integer): Integer;
  611.  
  612. { DeleteFile deletes the file given by FileName. The return value is True if
  613.   the file was successfully deleted, or False if an error occurred. }
  614.  
  615. function DeleteFile(const FileName: string): Boolean;
  616.  
  617. { RenameFile renames the file given by OldName to the name given by NewName.
  618.   The return value is True if the file was successfully renamed, or False if
  619.   an error occurred. }
  620.  
  621. function RenameFile(const OldName, NewName: string): Boolean;
  622.  
  623. { ChangeFileExt changes the extension of a filename. FileName specifies a
  624.   filename with or without an extension, and Extension specifies the new
  625.   extension for the filename. The new extension can be a an empty string or
  626.   a period followed by up to three characters. }
  627.  
  628. function ChangeFileExt(const FileName, Extension: string): string;
  629.  
  630. { ExtractFilePath extracts the drive and directory parts of the given
  631.   filename. The resulting string is the rightmost characters of FileName,
  632.   up to and including the colon or backslash that separates the path
  633.   information from the name and extension. The resulting string is empty
  634.   if FileName contains no drive and directory parts. }
  635.  
  636. function ExtractFilePath(const FileName: string): string;
  637.  
  638. { ExtractFileName extracts the name and extension parts of the given
  639.   filename. The resulting string is the leftmost characters of FileName,
  640.   starting with the first character after the colon or backslash that
  641.   separates the path information from the name and extension. The resulting
  642.   string is equal to FileName if FileName contains no drive and directory
  643.   parts. }
  644.  
  645. function ExtractFileName(const FileName: string): string;
  646.  
  647. { ExtractFileExt extracts the extension part of the given filename. The
  648.   resulting string includes the period character that separates the name
  649.   and extension parts. The resulting string is empty if the given filename
  650.   has no extension. }
  651.  
  652. function ExtractFileExt(const FileName: string): string;
  653.  
  654. { ExpandFileName expands the given filename to a fully qualified filename.
  655.   The resulting string consists of a drive letter, a colon, a root relative
  656.   directory path, and a filename, all in upper case characters. Embedded '.'
  657.   and '..' directory references are removed. }
  658.  
  659. function ExpandFileName(const FileName: string): string;
  660.  
  661. { FileSearch searches for the file given by Name in the list of directories
  662.   given by DirList. The directory paths in DirList must be separated by
  663.   semicolons. The search always starts with the current directory of the
  664.   current drive. The returned value is a concatenation of one of the
  665.   directory paths and the filename, or an empty string if the file could not
  666.   be located. }
  667.  
  668. function FileSearch(const Name, DirList: string): string;
  669.  
  670. { DiskFree returns the number of free bytes on the specified drive number,
  671.   where 0 = Current, 1 = A, 2 = B, etc. DiskFree returns -1 if the drive
  672.   number is invalid. }
  673.  
  674. function DiskFree(Drive: Byte): Longint;
  675.  
  676. { DiskSize returns the size in bytes of the specified drive number, where
  677.   0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number
  678.   is invalid. }
  679.  
  680. function DiskSize(Drive: Byte): Longint;
  681.  
  682. { FileDateToDateTime converts a DOS date-and-time value to a TDateTime
  683.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  684.   date-and-time values, and the Time field of a TSearchRec used by the
  685.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  686.  
  687. function FileDateToDateTime(FileDate: Longint): TDateTime;
  688.  
  689. { DateTimeToFileDate converts a TDateTime value to a DOS date-and-time
  690.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  691.   date-and-time values, and the Time field of a TSearchRec used by the
  692.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  693.  
  694. function DateTimeToFileDate(DateTime: TDateTime): Longint;
  695.  
  696. { PChar routines }
  697.  
  698. { StrLen returns the number of characters in Str, not counting the null
  699.   terminator. }
  700.  
  701. function StrLen(Str: PChar): Cardinal;
  702.  
  703. { StrEnd returns a pointer to the null character that terminates Str. }
  704.  
  705. function StrEnd(Str: PChar): PChar;
  706.  
  707. { StrMove copies exactly Count characters from Source to Dest and returns
  708.   Dest. Source and Dest may overlap. }
  709.  
  710. function StrMove(Dest, Source: PChar; Count: Cardinal): PChar;
  711.  
  712. { StrCopy copies Source to Dest and returns Dest. }
  713.  
  714. function StrCopy(Dest, Source: PChar): PChar;
  715.  
  716. { StrECopy copies Source to Dest and returns StrEnd(Dest). }
  717.  
  718. function StrECopy(Dest, Source: PChar): PChar;
  719.  
  720. { StrLCopy copies at most MaxLen characters from Source to Dest and
  721.   returns Dest. }
  722.  
  723. function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  724.  
  725. { StrPCopy copies the Pascal style string Source into Dest and
  726.   returns Dest. }
  727.  
  728. function StrPCopy(Dest: PChar; const Source: String): PChar;
  729.  
  730. { StrPLCopy copies at most MaxLen characters from the Pascal style string
  731.   Source into Dest and returns Dest. }
  732.  
  733. function StrPLCopy(Dest: PChar; const Source: string; MaxLen: Cardinal): PChar;
  734.  
  735. { StrCat appends a copy of Source to the end of Dest and returns Dest. }
  736.  
  737. function StrCat(Dest, Source: PChar): PChar;
  738.  
  739. { StrLCat appends at most MaxLen - StrLen(Dest) characters from Source to
  740.   the end of Dest, and returns Dest. }
  741.  
  742. function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  743.  
  744. { StrComp compares Str1 to Str2. The return value is less than 0 if
  745.   Str1 < Str2, 0 if Str1 = Str2, or greater than 0 if Str1 > Str2. }
  746.  
  747. function StrComp(Str1, Str2: PChar): Integer;
  748.  
  749. { StrIComp compares Str1 to Str2, without case sensitivity. The return
  750.   value is the same as StrComp. }
  751.  
  752. function StrIComp(Str1, Str2: PChar): Integer;
  753.  
  754. { StrLComp compares Str1 to Str2, for a maximum length of MaxLen
  755.   characters. The return value is the same as StrComp. }
  756.  
  757. function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  758.  
  759. { StrLIComp compares Str1 to Str2, for a maximum length of MaxLen
  760.   characters, without case sensitivity. The return value is the same
  761.   as StrComp. }
  762.  
  763. function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  764.  
  765. { StrScan returns a pointer to the first occurrence of Chr in Str. If Chr
  766.   does not occur in Str, StrScan returns NIL. The null terminator is
  767.   considered to be part of the string. }
  768.  
  769. function StrScan(Str: PChar; Chr: Char): PChar;
  770.  
  771. { StrRScan returns a pointer to the last occurrence of Chr in Str. If Chr
  772.   does not occur in Str, StrRScan returns NIL. The null terminator is
  773.   considered to be part of the string. }
  774.  
  775. function StrRScan(Str: PChar; Chr: Char): PChar;
  776.  
  777. { StrPos returns a pointer to the first occurrence of Str2 in Str1. If
  778.   Str2 does not occur in Str1, StrPos returns NIL. }
  779.  
  780. function StrPos(Str1, Str2: PChar): PChar;
  781.  
  782. { StrUpper converts Str to upper case and returns Str. }
  783.  
  784. function StrUpper(Str: PChar): PChar;
  785.  
  786. { StrLower converts Str to lower case and returns Str. }
  787.  
  788. function StrLower(Str: PChar): PChar;
  789.  
  790. { StrPas converts Str to a Pascal style string. }
  791.  
  792. function StrPas(Str: PChar): String;
  793.  
  794. { StrAlloc allocates a buffer of the given size on the heap. The size of
  795.   the allocated buffer is encoded in a two byte header that immediately
  796.   preceeds the buffer. To dispose the buffer, use StrDispose. }
  797.  
  798. function StrAlloc(Size: Cardinal): PChar;
  799.  
  800. { StrBufSize returns the allocated size of the given buffer, not including
  801.   the two byte header. }
  802.  
  803. function StrBufSize(Str: PChar): Cardinal;
  804.  
  805. { StrNew allocates a copy of Str on the heap. If Str is NIL, StrNew returns
  806.   NIL and doesn't allocate any heap space. Otherwise, StrNew makes a
  807.   duplicate of Str, obtaining space with a call to the StrAlloc function,
  808.   and returns a pointer to the duplicated string. To dispose the string,
  809.   use StrDispose. }
  810.  
  811. function StrNew(Str: PChar): PChar;
  812.  
  813. { StrDispose disposes a string that was previously allocated with StrAlloc
  814.   or StrNew. If Str is NIL, StrDispose does nothing. }
  815.  
  816. procedure StrDispose(Str: PChar);
  817.  
  818. { String formatting routines }
  819.  
  820. { The Format routine formats the argument list given by the Args parameter
  821.   using the format string given by the Format parameter.
  822.  
  823.   Format strings contain two types of objects--plain characters and format
  824.   specifiers. Plain characters are copied verbatim to the resulting string.
  825.   Format specifiers fetch arguments from the argument list and apply
  826.   formatting to them.
  827.  
  828.   Format specifiers have the following form:
  829.  
  830.     "%" [index ":"] ["-"] [width] ["." prec] type
  831.  
  832.   A format specifier begins with a % character. After the % come the
  833.   following, in this order:
  834.  
  835.   -  an optional argument index specifier, [index ":"]
  836.   -  an optional left-justification indicator, ["-"]
  837.   -  an optional width specifier, [width]
  838.   -  an optional precision specifier, ["." prec]
  839.   -  the conversion type character, type
  840.  
  841.   The following conversion characters are supported:
  842.  
  843.   d  Decimal. The argument must be an integer value. The value is converted
  844.      to a string of decimal digits. If the format string contains a precision
  845.      specifier, it indicates that the resulting string must contain at least
  846.      the specified number of digits; if the value has less digits, the
  847.      resulting string is left-padded with zeros.
  848.  
  849.   e  Scientific. The argument must be a floating-point value. The value is
  850.      converted to a string of the form "-d.ddd...E+ddd". The resulting
  851.      string starts with a minus sign if the number is negative, and one digit
  852.      always precedes the decimal point. The total number of digits in the
  853.      resulting string (including the one before the decimal point) is given
  854.      by the precision specifer in the format string--a default precision of
  855.      15 is assumed if no precision specifer is present. The "E" exponent
  856.      character in the resulting string is always followed by a plus or minus
  857.      sign and at least three digits.
  858.  
  859.   f  Fixed. The argument must be a floating-point value. The value is
  860.      converted to a string of the form "-ddd.ddd...". The resulting string
  861.      starts with a minus sign if the number is negative. The number of digits
  862.      after the decimal point is given by the precision specifier in the
  863.      format string--a default of 2 decimal digits is assumed if no precision
  864.      specifier is present.
  865.  
  866.   g  General. The argument must be a floating-point value. The value is
  867.      converted to the shortest possible decimal string using fixed or
  868.      scientific format. The number of significant digits in the resulting
  869.      string is given by the precision specifier in the format string--a
  870.      default precision of 15 is assumed if no precision specifier is present.
  871.      Trailing zeros are removed from the resulting string, and a decimal
  872.      point appears only if necessary. The resulting string uses fixed point
  873.      format if the number of digits to the left of the decimal point in the
  874.      value is less than or equal to the specified precision, and if the
  875.      value is greater than or equal to 0.00001. Otherwise the resulting
  876.      string uses scientific format.
  877.  
  878.   n  Number. The argument must be a floating-point value. The value is
  879.      converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format
  880.      corresponds to the "f" format, except that the resulting string
  881.      contains thousand separators.
  882.  
  883.   m  Money. The argument must be a floating-point value. The value is
  884.      converted to a string that represents a currency amount. The conversion
  885.      is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat,
  886.      ThousandSeparator, DecimalSeparator, and CurrencyDecimals global
  887.      variables, all of which are initialized from the Currency Format in
  888.      the International section of the Windows Control Panel. If the format
  889.      string contains a precision specifier, it overrides the value given
  890.      by the CurrencyDecimals global variable.
  891.  
  892.   p  Pointer. The argument must be a pointer value. The value is converted
  893.      to a string of the form "XXXX:YYYY" where XXXX and YYYY are the
  894.      segment and offset parts of the pointer expressed as four hexadecimal
  895.      digits.
  896.  
  897.   s  String. The argument must be a character, a string, or a PChar value.
  898.      The string or character is inserted in place of the format specifier.
  899.      The precision specifier, if present in the format string, specifies the
  900.      maximum length of the resulting string. If the argument is a string
  901.      that is longer than this maximum, the string is truncated.
  902.  
  903.   x  Hexadecimal. The argument must be an integer value. The value is
  904.      converted to a string of hexadecimal digits. If the format string
  905.      contains a precision specifier, it indicates that the resulting string
  906.      must contain at least the specified number of digits; if the value has
  907.      less digits, the resulting string is left-padded with zeros.
  908.  
  909.   Conversion characters may be specified in upper case as well as in lower
  910.   case--both produce the same results.
  911.  
  912.   For all floating-point formats, the actual characters used as decimal and
  913.   thousand separators are obtained from the DecimalSeparator and
  914.   ThousandSeparator global variables.
  915.  
  916.   Index, width, and precision specifiers can be specified directly using
  917.   decimal digit string (for example "%10d"), or indirectly using an asterisk
  918.   charcater (for example "%*.*f"). When using an asterisk, the next argument
  919.   in the argument list (which must be an integer value) becomes the value
  920.   that is actually used. For example "Format('%*.*f', [8, 2, 123.456])" is
  921.   the same as "Format('%8.2f', [123.456])".
  922.  
  923.   A width specifier sets the minimum field width for a conversion. If the
  924.   resulting string is shorter than the minimum field width, it is padded
  925.   with blanks to increase the field width. The default is to right-justify
  926.   the result by adding blanks in front of the value, but if the format
  927.   specifier contains a left-justification indicator (a "-" character
  928.   preceding the width specifier), the result is left-justified by adding
  929.   blanks after the value.
  930.  
  931.   An index specifier sets the current argument list index to the specified
  932.   value. The index of the first argument in the argument list is 0. Using
  933.   index specifiers, it is possible to format the same argument multiple
  934.   times. For example "Format('%d %d %0:d %d', [10, 20])" produces the string
  935.   '10 20 10 20'.
  936.  
  937.   The Format function can be combined with other formatting functions. For
  938.   example
  939.  
  940.     S := Format('Your total was %s on %s', [
  941.       FormatFloat('$#,##0.00;;zero', Total),
  942.       FormatDateTime('mm/dd/yy', Date)]);
  943.  
  944.   which uses the FormatFloat and FormatDateTime functions to customize the
  945.   format beyond what is possible with Format. }
  946.  
  947. function Format(const Format: string; const Args: array of const): string;
  948.  
  949. { FmtStr formats the argument list given by Args using the format string
  950.   given by Format into the string variable given by Result. For further
  951.   details, see the description of the Format function. }
  952.  
  953. procedure FmtStr(var Result: string; const Format: string;
  954.   const Args: array of const);
  955.  
  956. { StrFmt formats the argument list given by Args using the format string
  957.   given by Format into the buffer given by Buffer. It is up to the caller to
  958.   ensure that Buffer is large enough for the resulting string. The returned
  959.   value is Buffer. For further details, see the description of the Format
  960.   function. }
  961.  
  962. function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
  963.  
  964. { StrFmt formats the argument list given by Args using the format string
  965.   given by Format into the buffer given by Buffer. The resulting string will
  966.   contain no more than MaxLen characters, not including the null terminator.
  967.   The returned value is Buffer. For further details, see the description of
  968.   the Format function. }
  969.  
  970. function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
  971.   const Args: array of const): PChar;
  972.  
  973. { FormatBuf formats the argument list given by Args using the format string
  974.   given by Format and FmtLen into the buffer given by Buffer and BufLen.
  975.   The Format parameter is a reference to a buffer containing FmtLen
  976.   characters, and the Buffer parameter is a reference to a buffer of BufLen
  977.   characters. The returned value is the number of characters actually stored
  978.   in Buffer. The returned value is always less than or equal to BufLen. For
  979.   further details, see the description of the Format function. }
  980.  
  981. function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
  982.   FmtLen: Cardinal; const Args: array of const): Cardinal;
  983.  
  984. { Floating point conversion routines }
  985.  
  986. { FloatToStr converts the floating-point value given by Value to its string
  987.   representation. The conversion uses general number format with 15
  988.   significant digits. For further details, see the description of the
  989.   FloatToStrF function. }
  990.  
  991. function FloatToStr(Value: Extended): string;
  992.  
  993. { FloatToStrF converts the floating-point value given by Value to its string
  994.   representation. The Format parameter controls the format of the resulting
  995.   string. The Precision parameter specifies the precision of the given value.
  996.   It should be 7 or less for values of type Single, 15 or less for values of
  997.   type Double, and 18 or less for values of type Extended. The meaning of the
  998.   Digits parameter depends on the particular format selected.
  999.  
  1000.   The possible values of the Format parameter, and the meaning of each, are
  1001.   described below.
  1002.  
  1003.   ffGeneral - General number format. The value is converted to the shortest
  1004.   possible decimal string using fixed or scientific format. Trailing zeros
  1005.   are removed from the resulting string, and a decimal point appears only
  1006.   if necessary. The resulting string uses fixed point format if the number
  1007.   of digits to the left of the decimal point in the value is less than or
  1008.   equal to the specified precision, and if the value is greater than or
  1009.   equal to 0.00001. Otherwise the resulting string uses scientific format,
  1010.   and the Digits parameter specifies the minimum number of digits in the
  1011.   exponent (between 0 and 4).
  1012.  
  1013.   ffExponent - Scientific format. The value is converted to a string of the
  1014.   form "-d.ddd...E+dddd". The resulting string starts with a minus sign if
  1015.   the number is negative, and one digit always precedes the decimal point.
  1016.   The total number of digits in the resulting string (including the one
  1017.   before the decimal point) is given by the Precision parameter. The "E"
  1018.   exponent character in the resulting string is always followed by a plus
  1019.   or minus sign and up to four digits. The Digits parameter specifies the
  1020.   minimum number of digits in the exponent (between 0 and 4).
  1021.  
  1022.   ffFixed - Fixed point format. The value is converted to a string of the
  1023.   form "-ddd.ddd...". The resulting string starts with a minus sign if the
  1024.   number is negative, and at least one digit always precedes the decimal
  1025.   point. The number of digits after the decimal point is given by the Digits
  1026.   parameter--it must be between 0 and 18. If the number of digits to the
  1027.   left of the decimal point is greater than the specified precision, the
  1028.   resulting value will use scientific format.
  1029.  
  1030.   ffNumber - Number format. The value is converted to a string of the form
  1031.   "-d,ddd,ddd.ddd...". The ffNumber format corresponds to the ffFixed format,
  1032.   except that the resulting string contains thousand separators.
  1033.  
  1034.   ffCurrency - Currency format. The value is converted to a string that
  1035.   represents a currency amount. The conversion is controlled by the
  1036.   CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, and
  1037.   DecimalSeparator global variables, all of which are initialized from the
  1038.   Currency Format in the International section of the Windows Control Panel.
  1039.   The number of digits after the decimal point is given by the Digits
  1040.   parameter--it must be between 0 and 18.
  1041.  
  1042.   For all formats, the actual characters used as decimal and thousand
  1043.   separators are obtained from the DecimalSeparator and ThousandSeparator
  1044.   global variables.
  1045.  
  1046.   If the given value is a NAN (not-a-number), the resulting string is 'NAN'.
  1047.   If the given value is positive infinity, the resulting string is 'INF'. If
  1048.   the given value is negative infinity, the resulting string is '-INF'. }
  1049.  
  1050. function FloatToStrF(Value: Extended; Format: TFloatFormat;
  1051.   Precision, Digits: Integer): string;
  1052.  
  1053. { FloatToText converts the given floating-point value to its decimal
  1054.   representation using the specified format, precision, and digits. The
  1055.   resulting string of characters is stored in the given buffer, and the
  1056.   returned value is the number of characters stored. The resulting string
  1057.   is not null-terminated. For further details, see the description of the
  1058.   FloatToStrF function. }
  1059.  
  1060. function FloatToText(Buffer: PChar; Value: Extended; Format: TFloatFormat;
  1061.   Precision, Digits: Integer): Integer;
  1062.  
  1063. { FormatFloat formats the floating-point value given by Value using the
  1064.   format string given by Format. The following format specifiers are
  1065.   supported in the format string:
  1066.  
  1067.   0     Digit placeholder. If the value being formatted has a digit in the
  1068.         position where the '0' appears in the format string, then that digit
  1069.         is copied to the output string. Otherwise, a '0' is stored in that
  1070.         position in the output string.
  1071.  
  1072.   #     Digit placeholder. If the value being formatted has a digit in the
  1073.         position where the '#' appears in the format string, then that digit
  1074.         is copied to the output string. Otherwise, nothing is stored in that
  1075.         position in the output string.
  1076.  
  1077.   .     Decimal point. The first '.' character in the format string
  1078.         determines the location of the decimal separator in the formatted
  1079.         value; any additional '.' characters are ignored. The actual
  1080.         character used as a the decimal separator in the output string is
  1081.         determined by the DecimalSeparator global variable. The default value
  1082.         of DecimalSeparator is specified in the Number Format of the
  1083.         International section in the Windows Control Panel.
  1084.  
  1085.   ,     Thousand separator. If the format string contains one or more ','
  1086.         characters, the output will have thousand separators inserted between
  1087.         each group of three digits to the left of the decimal point. The
  1088.         placement and number of ',' characters in the format string does not
  1089.         affect the output, except to indicate that thousand separators are
  1090.         wanted. The actual character used as a the thousand separator in the
  1091.         output is determined by the ThousandSeparator global variable. The
  1092.         default value of ThousandSeparator is specified in the Number Format
  1093.         of the International section in the Windows Control Panel.
  1094.  
  1095.   E+    Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-'
  1096.   E-    are contained in the format string, the number is formatted using
  1097.   e+    scientific notation. A group of up to four '0' characters can
  1098.   e-    immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the
  1099.         minimum number of digits in the exponent. The 'E+' and 'e+' formats
  1100.         cause a plus sign to be output for positive exponents and a minus
  1101.         sign to be output for negative exponents. The 'E-' and 'e-' formats
  1102.         output a sign character only for negative exponents.
  1103.  
  1104.   'xx'  Characters enclosed in single or double quotes are output as-is, and
  1105.   "xx"  do not affect formatting.
  1106.  
  1107.   ;     Separates sections for positive, negative, and zero numbers in the
  1108.         format string.
  1109.  
  1110.   The locations of the leftmost '0' before the decimal point in the format
  1111.   string and the rightmost '0' after the decimal point in the format string
  1112.   determine the range of digits that are always present in the output string.
  1113.  
  1114.   The number being formatted is always rounded to as many decimal places as
  1115.   there are digit placeholders ('0' or '#') to the right of the decimal
  1116.   point. If the format string contains no decimal point, the value being
  1117.   formatted is rounded to the nearest whole number.
  1118.  
  1119.   If the number being formatted has more digits to the left of the decimal
  1120.   separator than there are digit placeholders to the left of the '.'
  1121.   character in the format string, the extra digits are output before the
  1122.   first digit placeholder.
  1123.  
  1124.   To allow different formats for positive, negative, and zero values, the
  1125.   format string can contain between one and three sections separated by
  1126.   semicolons.
  1127.  
  1128.   One section - The format string applies to all values.
  1129.  
  1130.   Two sections - The first section applies to positive values and zeros, and
  1131.   the second section applies to negative values.
  1132.  
  1133.   Three sections - The first section applies to positive values, the second
  1134.   applies to negative values, and the third applies to zeros.
  1135.  
  1136.   If the section for negative values or the section for zero values is empty,
  1137.   that is if there is nothing between the semicolons that delimit the
  1138.   section, the section for positive values is used instead.
  1139.  
  1140.   If the section for positive values is empty, or if the entire format string
  1141.   is empty, the value is formatted using general floating-point formatting
  1142.   with 15 significant digits, corresponding to a call to FloatToStrF with
  1143.   the ffGeneral format. General floating-point formatting is also used if
  1144.   the value has more than 18 digits to the left of the decimal point and
  1145.   the format string does not specify scientific notation.
  1146.  
  1147.   The table below shows some sample formats and the results produced when
  1148.   the formats are applied to different values:
  1149.  
  1150.   Format string          1234        -1234       0.5         0
  1151.   -----------------------------------------------------------------------
  1152.                          1234        -1234       0.5         0
  1153.   0                      1234        -1234       1           0
  1154.   0.00                   1234.00     -1234.00    0.50        0.00
  1155.   #.##                   1234        -1234       .5
  1156.   #,##0.00               1,234.00    -1,234.00   0.50        0.00
  1157.   #,##0.00;(#,##0.00)    1,234.00    (1,234.00)  0.50        0.00
  1158.   #,##0.00;;Zero         1,234.00    -1,234.00   0.50        Zero
  1159.   0.000E+00              1.234E+03   -1.234E+03  5.000E-01   0.000E+00
  1160.   #.###E-0               1.234E3     -1.234E3    5E-1        0E0
  1161.   ----------------------------------------------------------------------- }
  1162.  
  1163. function FormatFloat(const Format: string; Value: Extended): string;
  1164.  
  1165. { FloatToTextFmt converts the given floating-point value to its decimal
  1166.   representation using the specified format. The resulting string of
  1167.   characters is stored in the given buffer, and the returned value is the
  1168.   number of characters stored. The resulting string is not null-terminated.
  1169.   For further details, see the description of the FormatFloat function. }
  1170.  
  1171. function FloatToTextFmt(Buffer: PChar; Value: Extended;
  1172.   Format: PChar): Integer;
  1173.  
  1174. { StrToFloat converts the given string to a floating-point value. The string
  1175.   must consist of an optional sign (+ or -), a string of digits with an
  1176.   optional decimal point, and an optional 'E' or 'e' followed by a signed
  1177.   integer. Leading and trailing blanks in the string are ignored. The
  1178.   DecimalSeparator global variable defines the character that must be used
  1179.   as a decimal point. Thousand separators and currency symbols are not
  1180.   allowed in the string. If the string doesn't contain a valid value, an
  1181.   EConvertError exception is raised. }
  1182.  
  1183. function StrToFloat(const S: string): Extended;
  1184.  
  1185. { TextToFloat converts the null-terminated string given by Buffer to a
  1186.   floating-point value which is returned in the variable given by Value. The
  1187.   return value is True if the conversion was successful, or False if the
  1188.   string is not a valid floating-point value. For further details, see the
  1189.   description of the StrToFloat function. }
  1190.  
  1191. function TextToFloat(Buffer: PChar; var Value: Extended): Boolean;
  1192.  
  1193. { FloatToDecimal converts a floating-point value to a decimal representation
  1194.   that is suited for further formatting. The Precision parameter specifies
  1195.   the requested number of significant digits in the result--the allowed
  1196.   range is 1..18. The Decimals parameter specifies the requested maximum
  1197.   number of digits to the left of the decimal point in the result. Precision
  1198.   and Decimals together control how the result is rounded. To produce a
  1199.   result that always has a given number of significant digits regardless of
  1200.   the magnitude of the number, specify 9999 for the Decimals parameter. The
  1201.   result of the conversion is stored in the specified TFloatRec record as
  1202.   follows:
  1203.  
  1204.   Exponent - Contains the magnitude of the number, i.e. the number of
  1205.   significant digits to the right of the decimal point. The Exponent field
  1206.   is negative if the absolute value of the number is less than one. If the
  1207.   number is a NAN (not-a-number), Exponent is set to -32768. If the number
  1208.   is INF or -INF (positive or negative infinity), Exponent is set to 32767.
  1209.  
  1210.   Negative - True if the number is negative, False if the number is zero
  1211.   or positive.
  1212.  
  1213.   Digits - Contains up to 18 significant digits followed by a null
  1214.   terminator. The implied decimal point (if any) is not stored in Digits.
  1215.   Trailing zeros are removed, and if the resulting number is zero, NAN, or
  1216.   INF, Digits contains nothing but the null terminator. }
  1217.  
  1218. procedure FloatToDecimal(var Result: TFloatRec; Value: Extended;
  1219.   Precision, Decimals: Integer);
  1220.  
  1221. { Date/time support routines }
  1222.  
  1223. { EncodeDate encodes the given year, month, and day into a TDateTime value.
  1224.   The year must be between 1 and 9999, the month must be between 1 and 12,
  1225.   and the day must be between 1 and N, where N is the number of days in the
  1226.   specified month. If the specified values are not within range, an
  1227.   EConvertError exception is raised. The resulting value is one plus the
  1228.   number of days between 1/1/0001 and the given date. }
  1229.  
  1230. function EncodeDate(Year, Month, Day: Word): TDateTime;
  1231.  
  1232. { EncodeTime encodes the given hour, minute, second, and millisecond into a
  1233.   TDateTime value. The hour must be between 0 and 23, the minute must be
  1234.   between 0 and 59, the second must be between 0 and 59, and the millisecond
  1235.   must be between 0 and 999. If the specified values are not within range, an
  1236.   EConvertError exception is raised. The resulting value is a number between
  1237.   0 (inclusive) and 1 (not inclusive) that indicates the fractional part of
  1238.   a day given by the specified time. The value 0 corresponds to midnight,
  1239.   0.5 corresponds to noon, 0.75 corresponds to 6:00 pm, etc. }
  1240.  
  1241. function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
  1242.  
  1243. { DecodeDate decodes the integral (date) part of the given TDateTime value
  1244.   into its corresponding year, month, and day. If the given TDateTime value
  1245.   is less than or equal to zero, the year, month, and day return parameters
  1246.   are all set to zero. }
  1247.  
  1248. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
  1249.  
  1250. { DecodeTime decodes the fractional (time) part of the given TDateTime value
  1251.   into its corresponding hour, minute, second, and millisecond. }
  1252.  
  1253. procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
  1254.  
  1255. { DayOfWeek returns the day of the week of the given date. The result is an
  1256.   integer between 1 and 7, corresponding to Sunday through Saturday. }
  1257.  
  1258. function DayOfWeek(Date: TDateTime): Integer;
  1259.  
  1260. { Date returns the current date. }
  1261.  
  1262. function Date: TDateTime;
  1263.  
  1264. { Time returns the current time. }
  1265.  
  1266. function Time: TDateTime;
  1267.  
  1268. { Now returns the current date and time, corresponding to Date + Time. }
  1269.  
  1270. function Now: TDateTime;
  1271.  
  1272. { DateToStr converts the date part of the given TDateTime value to a string.
  1273.   The conversion uses the format specified by the ShortDateFormat global
  1274.   variable. }
  1275.  
  1276. function DateToStr(Date: TDateTime): string;
  1277.  
  1278. { TimeToStr converts the time part of the given TDateTime value to a string.
  1279.   The conversion uses the format specified by the LongTimeFormat global
  1280.   variable. }
  1281.  
  1282. function TimeToStr(Time: TDateTime): string;
  1283.  
  1284. { DateTimeToStr converts the given date and time to a string. The resulting
  1285.   string consists of a date and time formatted using the ShortDateFormat and
  1286.   LongTimeFormat global variables. Time information is included in the
  1287.   resulting string only if the fractional part of the given date and time
  1288.   value is non-zero. }
  1289.  
  1290. function DateTimeToStr(DateTime: TDateTime): string;
  1291.  
  1292. { StrToDate converts the given string to a date value. The string must
  1293.   consist of two or three numbers, separated by the character defined by
  1294.   the DateSeparator global variable. The order for month, day, and year is
  1295.   determined by the ShortDateFormat global variable--possible combinations
  1296.   are m/d/y, d/m/y, and y/m/d. If the string contains only two numbers, it
  1297.   is interpreted as a date (m/d or d/m) in the current year. Year values
  1298.   between 0 and 99 are assumed to mean 1900 to 1999. If the given string
  1299.   does not contain a valid date, an EConvertError exception is raised. }
  1300.  
  1301. function StrToDate(const S: string): TDateTime;
  1302.  
  1303. { StrToTime converts the given string to a time value. The string must
  1304.   consist of two or three numbers, separated by the character defined by
  1305.   the TimeSeparator global variable, optionally followed by an AM or PM
  1306.   indicator. The numbers represent hour, minute, and (optionally) second,
  1307.   in that order. If the time is followed by AM or PM, it is assumed to be
  1308.   in 12-hour clock format. If no AM or PM indicator is included, the time
  1309.   is assumed to be in 24-hour clock format. If the given string does not
  1310.   contain a valid time, an EConvertError exception is raised. }
  1311.  
  1312. function StrToTime(const S: string): TDateTime;
  1313.  
  1314. { StrToDateTime converts the given string to a date and time value. The
  1315.   string must contain a date optionally followed by a time. The date and
  1316.   time parts of the string must follow the formats described for the
  1317.   StrToDate and StrToTime functions. }
  1318.  
  1319. function StrToDateTime(const S: string): TDateTime;
  1320.  
  1321. { FormatDateTime formats the date-and-time value given by DateTime using the
  1322.   format given by Format. The following format specifiers are supported:
  1323.  
  1324.   c       Displays the date using the format given by the ShortDateFormat
  1325.           global variable, followed by the time using the format given by
  1326.           the LongTimeFormat global variable. The time is not displayed if
  1327.           the fractional part of the DateTime value is zero.
  1328.  
  1329.   d       Displays the day as a number without a leading zero (1-31).
  1330.  
  1331.   dd      Displays the day as a number with a leading zero (01-31).
  1332.  
  1333.   ddd     Displays the day as an abbreviation (Sun-Sat) using the strings
  1334.           given by the ShortDayNames global variable.
  1335.  
  1336.   dddd    Displays the day as a full name (Sunday-Saturday) using the strings
  1337.           given by the LongDayNames global variable.
  1338.  
  1339.   ddddd   Displays the date using the format given by the ShortDateFormat
  1340.           global variable.
  1341.  
  1342.   dddddd  Displays the date using the format given by the LongDateFormat
  1343.           global variable.
  1344.  
  1345.   aaa     曜日を日本語の省略形で表示します (日-土)
  1346.  
  1347.   aaaa    曜日を日本語で表示します (日曜日-土曜日)
  1348.   
  1349.   m       Displays the month as a number without a leading zero (1-12). If
  1350.           the m specifier immediately follows an h or hh specifier, the
  1351.           minute rather than the month is displayed.
  1352.  
  1353.   mm      Displays the month as a number with a leading zero (01-12). If
  1354.           the mm specifier immediately follows an h or hh specifier, the
  1355.           minute rather than the month is displayed.
  1356.  
  1357.   mmm     Displays the month as an abbreviation (Jan-Dec) using the strings
  1358.           given by the ShortMonthNames global variable.
  1359.  
  1360.   mmmm    Displays the month as a full name (January-December) using the
  1361.           strings given by the LongMonthNames global variable.
  1362.  
  1363.   yy      Displays the year as a two-digit number (00-99).
  1364.  
  1365.   yyyy    Displays the year as a four-digit number (0000-9999).
  1366.  
  1367.   g       年号の頭文字を英字で表示します (M, T, S, H)
  1368.  
  1369.   gg      年号の先頭1文字を表示します (明, 大, 昭, 平)
  1370.  
  1371.   ggg     年号の先頭1文字を表示します (明治, 大正, 昭和, 平成)
  1372.  
  1373.   e       年号を元にした年を0を付けずに表示します
  1374.  
  1375.   ee      年号を元にした年を2桁で表示します
  1376.  
  1377.   h       Displays the hour without a leading zero (0-23).
  1378.  
  1379.   hh      Displays the hour with a leading zero (00-23).
  1380.  
  1381.   n       Displays the minute without a leading zero (0-59).
  1382.  
  1383.   nn      Displays the minute with a leading zero (00-59).
  1384.  
  1385.   s       Displays the second without a leading zero (0-59).
  1386.  
  1387.   ss      Displays the second with a leading zero (00-59).
  1388.  
  1389.   t       Displays the time using the format given by the ShortTimeFormat
  1390.           global variable.
  1391.  
  1392.   tt      Displays the time using the format given by the LongTimeFormat
  1393.           global variable.
  1394.  
  1395.   am/pm   Uses the 12-hour clock for the preceding h or hh specifier, and
  1396.           displays 'am' for any hour before noon, and 'pm' for any hour
  1397.           after noon. The am/pm specifier can use lower, upper, or mixed
  1398.           case, and the result is displayed accordingly.
  1399.  
  1400.   a/p     Uses the 12-hour clock for the preceding h or hh specifier, and
  1401.           displays 'a' for any hour before noon, and 'p' for any hour after
  1402.           noon. The a/p specifier can use lower, upper, or mixed case, and
  1403.           the result is displayed accordingly.
  1404.  
  1405.   ampm    Uses the 12-hour clock for the preceding h or hh specifier, and
  1406.           displays the contents of the TimeAMString global variable for any
  1407.           hour before noon, and the contents of the TimePMString global
  1408.           variable for any hour after noon.
  1409.  
  1410.   /       Displays the date separator character given by the DateSeparator
  1411.           global variable.
  1412.  
  1413.   :       Displays the time separator character given by the TimeSeparator
  1414.           global variable.
  1415.  
  1416.   'xx'    Characters enclosed in single or double quotes are displayed as-is,
  1417.   "xx"    and do not affect formatting.
  1418.  
  1419.   Format specifiers may be written in upper case as well as in lower case
  1420.   letters--both produce the same result.
  1421.  
  1422.   If the string given by the Format parameter is empty, the date and time
  1423.   value is formatted as if a 'c' format specifier had been given.
  1424.  
  1425.   The following example:
  1426.  
  1427.     S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' +
  1428.       '"at" hh:mm AM/PM', StrToDateTime('2/15/95 10:30am'));
  1429.  
  1430.   assigns 'The meeting is on Wednesday, February 15, 1995 at 10:30 AM' to
  1431.   the string variable S. }
  1432.  
  1433. function FormatDateTime(const Format: string; DateTime: TDateTime): string;
  1434.  
  1435. { DateTimeToString converts the date and time value given by DateTime using
  1436.   the format string given by Format into the string variable given by Result.
  1437.   For further details, see the description of the FormatDateTime function. }
  1438.  
  1439. procedure DateTimeToString(var Result: string; const Format: string;
  1440.   DateTime: TDateTime);
  1441.  
  1442.  
  1443. { Initialization file support }
  1444.  
  1445. function GetProfileStr(Section, Entry: PChar; const Default: string): string;
  1446. function GetProfileChar(Section, Entry: PChar; Default: Char): Char;
  1447.  
  1448.  
  1449. procedure GetFormatSettings;
  1450.  
  1451. { Exception handling routines }
  1452.  
  1453. function ExceptObject: TObject;
  1454. function ExceptAddr: Pointer;
  1455.  
  1456. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  1457.  
  1458. procedure Abort;
  1459.  
  1460. procedure OutOfMemoryError;
  1461.  
  1462.  
  1463. procedure DefaultExceptHandler(FaultID: Word; ErrorAddr: Pointer);
  1464. procedure EnableExceptionHandler(Enable: Boolean);
  1465.  
  1466.  
  1467. implementation
  1468.